-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(form): fixed dynamic rendering of form default data #3145
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l123wx
requested review from
honkinglin,
uyarn,
carolin913,
HaixingOoO,
NWYLZW and
ZWkang
as code owners
October 17, 2024 03:51
l123wx
changed the title
chore(form): fixed variable naming misspellings
fix(form): fixed dynamic rendering of form default data
Oct 17, 2024
@HaixingOoO @honkinglin 一起看看呢 |
好 |
- 将 floatingFormDataRef 移至 formContext - 将 FormItem 渲染后删除对应游离值的逻辑移至 userFormItemInitialData hook 内
@l123wx 需要解决下冲突再更新下快照 |
/update-snapshot |
⏳ 正在运行快照更新。。。 CI: Open |
@uyarn 是要合并一下主分支的代码吗 第一次给这个仓库提pr,不太清楚流程,不好意思😂 |
@l123wx 嗯 不过上面已经通过机器人已经更新好了 |
/update-common |
uyarn
approved these changes
Oct 30, 2024
Merged
16 tasks
uyarn
reviewed
Dec 12, 2024
|
||
nameLists.forEach((nameList) => { | ||
const fieldValue = get(fields, nameList); | ||
const formItemRef = formMapRef.current.get(nameList.length > 1 ? nameList : nameList[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方这样处理会用问题,多级name的key是个数组,数组内存不一样 get的方式会取不到 导致对多级name setFieldValues 会失败
16 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤔 这个 PR 的性质是?
🔗 相关 Issue
#3076
💡 需求背景和解决方案
由于 Form 没有维护 formData 来管理表单的数据,而是直接使用 FormItem 中的 state 来记录,所以对于动态条件渲染的组件,如果使用 setFieldsValue 同时设置:1. 涉及判断条件的 fieldValue,2. 暂未渲染出来的 formItem 的值,结果跟用户的预期不一致。
所以在 Form 中创建了一个 游离值 formData,来记录这种临时的值。因为这类值预期是要被设置到对应组件上的,但是由于组件还没渲染,它们还没找到自己的归属,所以把它们叫做游离值(floatingFormData)哈哈
当使用 setFieldsValue 设置值时,会判断设置值对应的 FormItem 组件存不存在,如果不存在,就会把值记录到 FormItem 组件中。如果 组件不存在,但是游离值中已经有这个值了,会更新这个游离值。
当组件渲染时,会判断是否存在游离值,如果存在,则设置为组件的 initialData,优先级最高。当游离值被使用过后,会从游离
formData 中删除。
📝 更新日志
fix(Form): 修复了动态渲染表单无法使用 setFieldsValue 预设数据的问题
本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单